#ifndef _GL_DEPTH_STENCIL_H_
#define _GL_DEPTH_STENCIL_H_

#include "..\glew\glew.h"

#include "..\cuCommon\cuTypes.h"

typedef enum GL_COMPARISON_FUNC
{
    GL_COMPARISON_NEVER         = GL_NEVER,
    GL_COMPARISON_LESS          = GL_LESS,
    GL_COMPARISON_EQUAL         = GL_EQUAL,
    GL_COMPARISON_LESS_EQUAL    = GL_LEQUAL,
    GL_COMPARISON_GREATER       = GL_GREATER,
    GL_COMPARISON_NOT_EQUAL     = GL_NOTEQUAL,
    GL_COMPARISON_GREATER_EQUAL = GL_GEQUAL,
    GL_COMPARISON_ALWAYS        = GL_ALWAYS,
} GL_COMPARISON_FUNC;

typedef enum GL_STENCIL_OP
{
    GL_STENCIL_OP_KEEP          = GL_KEEP,
    GL_STENCIL_OP_ZERO          = GL_ZERO,
    GL_STENCIL_OP_REPLACE       = GL_REPLACE,
    GL_STENCIL_OP_INCR          = GL_INCR,
    GL_STENCIL_OP_DECR          = GL_DECR,
    GL_STENCIL_OP_INVERT        = GL_INVERT,
} GL_STENCIL_OP;

typedef struct GL_DEPTH_STENCILOP_DESC 
{
    GL_STENCIL_OP StencilFailOp;
    GL_STENCIL_OP StencilDepthFailOp;
    GL_STENCIL_OP StencilPassOp;
    GL_COMPARISON_FUNC StencilFunc;

    GL_DEPTH_STENCILOP_DESC()
    {
        StencilFailOp      = GL_STENCIL_OP_KEEP;
        StencilDepthFailOp = GL_STENCIL_OP_KEEP;
        StencilPassOp      = GL_STENCIL_OP_KEEP;
        
        StencilFunc = GL_COMPARISON_ALWAYS;
    }
} GL_DEPTH_STENCILOP_DESC;

typedef struct GL_DEPTH_STENCIL_DESC 
{
    bool   DepthEnable;
    bool   DepthWriteMask;
    GLenum DepthFunc;

    bool   StencilEnable;
    uint8  StencilReadMask;
    uint8  StencilWriteMask;

    GL_DEPTH_STENCILOP_DESC FrontFace;
    GL_DEPTH_STENCILOP_DESC BackFace;

    GL_DEPTH_STENCIL_DESC() :
        FrontFace(), BackFace()
    {
        DepthEnable = true;
        DepthWriteMask = 1;
        DepthFunc = GL_COMPARISON_LESS;

        StencilEnable    = false;
        StencilReadMask  = 0xFF;
        StencilWriteMask = 0xFF;

    }
} GL_DEPTH_STENCIL_DESC;

void glSetDepthStencilState(const GL_DEPTH_STENCIL_DESC * pDesc, uint32 StencilRef);

#endif